<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        margin: 100px auto;
        width: 800px;
        height: 800px;
        text-align: center;
        /* border: 1px red solid; */
      }
    </style>
  </head>
  <body>
    <div>
      <h1>2023年高考倒计时：</h1>
      <h1 id="Lasttime"></h1>
    </div>
    <script>
      //指定赋值显示倒计时地方；
      var Lasttime = document.getElementById("Lasttime");
      // 指定高考时间
      var GkDate = new Date("2023-6-7 9:00:00");
      var GkSec = Date.parse(GkDate);
      var nowSec, allSec, day, hours, minutes, seconds;
      var lastT = setInterval(function () {
        // 当前时间时间戳（秒）
        nowSec = Date.parse(new Date());
        // 算出总时差，以秒计算
        allSec = (GkSec - nowSec) / 1000;
        if (allSec >= 0) {
          // 算出天数
          day = parseInt(allSec / (24 * 60 * 60));
          //   算出小时
          hours = parseInt((allSec % (24 * 60 * 60)) / (60 * 60));
          //   算出分钟
          minutes = parseInt(((allSec % (24 * 60 * 60)) % (60 * 60)) / 60);
          //   算出秒数
          seconds = ((allSec % (24 * 60 * 60)) % (60 * 60)) % 60;
          //   赋值显示
          Lasttime.innerHTML = fornt(day) + "天" + fornt(hours) + "时" + fornt(minutes) + "分" + fornt(seconds) + "秒";
        } else {
          clearInterval(lastT);
        }
      }, 1000);
      //   一位数前面加"0"
      function fornt(a) {
        if (a < 10) {
          return "0" + a;
        } else {
          return a;
        }
      }
    </script>
  </body>
</html>
